<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=basePath%>css/weui.css">
<link rel="stylesheet" href="<%=basePath%>css/example.css">
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<title>real进歌后台管理系统</title>
</head>
<body style="background-color: #179B16;">
	<div class="weui-toptips weui-toptips_warn js_tooltips" style="display: none;" id="errorTips">未知错误</div>

	<br>
	<h2 style="text-align: center; color: #FFFFFF">题目列表</h2>

	<c:forEach items="${questionList }" var="question" varStatus="varStatus1">
		<div class="weui-cells__title" style="color: #FFFFFF;">题目类型</div>
		<div class="weui-cells" style="background-color: #9ED99D;">
			<div class="weui-cell weui-cell_select weui-cell_select-after">
				<div class="weui-cell__bd">
					<select class="weui-select" id="typeCode" id="typeCode" name="typeCode" disabled="disabled">
						<option value="">请选择题目类型</option>
						<c:forEach items="${typeList }" var="type" varStatus="varStatus">
							<option value="${type.typeCode }" <c:if test="${question.typeCode eq type.typeCode}">selected="selected"</c:if>>${type.typeName }</option>
						</c:forEach>
					</select>
				</div>
			</div>
		</div>
		<div class="weui-cells__title" style="color: #FFFFFF;">题目内容</div>
		<div class="weui-cells weui-cells_form" style="background-color: #9ED99D;">
			<div class="weui-cell">
				<div class="weui-cell__bd">${question.questionContent }</div>
			</div>
		</div>
		<div class="weui-cells__title" style="color: #FFFFFF;" onclick="showAnswer('answerId${varStatus1.count }${varStatus2.count }');">选项和答案</div>
		<div class="weui-cells weui-cells_radio" id="answerId${varStatus1.count }${varStatus2.count }" style="background-color: #9ED99D; display: none;">
			<c:forEach items="${question.answerList }" var="answer" varStatus="varStatus2">
				<label class="weui-cell weui-check__label" for="x${varStatus1.count }${varStatus2.count }" style="background-color: #9ED99D;">
					<div class="weui-cell__bd">
						<p>${answer.answer }</p>
					</div>
					<div class="weui-cell__ft">
						<input type="radio" class="weui-check" name="radio${varStatus1.count }" id="x${varStatus1.count }${varStatus2.count }" <c:if test="${question.answer eq answer.id}">checked="checked"</c:if> disabled="disabled">
						<span class="weui-icon-checked"></span>
					</div>
				</label>
			</c:forEach>
		</div>
		<div class="weui-cells__title" style="color: #FFFFFF;" onclick="showAnswer('descId${varStatus1.count }${varStatus2.count }');">题目描述</div>
		<div class="weui-cells weui-cells_form" id="descId${varStatus1.count }${varStatus2.count }" style="background-color: #9ED99D; display: none;">
			<div class="weui-cell" style="background-color: #9ED99D;">
				<div class="weui-cell__bd">${question.questionDesc }</div>
			</div>
		</div>
		<div class="button-sp-area" style="background-color: #9ED99D;" align="center">
			<c:if test="${'02' ne question.status }">
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" onclick="onStatus('${question.questionNo }', '02');">激活</a>
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_warn">删除</a>
			</c:if>
			<c:if test="${'02' eq question.status }">
				<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="onStatus('${question.questionNo }', '01');">禁用</a>
			</c:if>
			<br>
		</div>
	</c:forEach>
	
	<div class="weui-footer">
		<p class="weui-footer__links">
			<a href="<%=basePath%>index.do" class="weui-footer__link">realQuestion</a>
		</p>
		<p class="weui-footer__text">Copyright © 2018 question.realjinge.com</p>
	</div>
</body>

<script type="text/javascript">
	function showAnswer(id) {
		if (document.getElementById(id).style.display == "none") {
			document.getElementById(id).style.display = "inline";
		} else {
			document.getElementById(id).style.display = "none"
		}
	}
	
	function onStatus(questionNo, status) {
		$.ajax({
			url : '<%=basePath%>/admin/updateQuestionStatus.do',
			async : true,
			type : "POST",
			data : {"questionNo" : questionNo, "status" : status},
			dataType : 'json',
			success : function(data) {
				var ret = data.errCode;
				if (ret == 0) {
					// 刷新当前页面
					location.reload();
				} else {
					alert('系统错误！');
				}
			}
		});
	}
</script>

</html>